package zhuce;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class weibo {
public int name(Set<User>u,String s) {
	Iterator<User> users=u.iterator();
	int i=0;
	while(users.hasNext()){
		if(users.next().getUserName().equals(s)){
			i=0;
		}
		else{
			i=1;
		}
	}
	return i;
}
public int passWord(Set<User> u,String s,String res){
	if(s.equals(res)){
		return 1;
	}else{
		return 0;
	}
}
public int birth(Set<User> u,String bir){
	String pat="\\d{4}-\\d{2}-\\d{2}";
	Pattern p=Pattern.compile(pat);
	Matcher m=p.matcher(bir);
	if(m.matches()){
		return 1;
	}else{
		return 0;
	}
}
public int phone(Set<User> u,String ph){
	int f=0;
	String pat="1[3||5||7||8]\\d{9}";
	Pattern p =Pattern.compile(pat);
	Matcher m=p.matcher(ph);
	if(m.matches()){
		if(checkTel(u,ph)==1){
			f=1;
		}else{
			f=-1;
		}
		return f;
	}else{
		return 0;
	}
	
}
public int checkTel(Set<User> u,String cs){
	int f=0;
	Iterator<User> users= u.iterator();
	while(users.hasNext()){
		if(users.next().getPhone().equals(cs)){
			f=1;
		}
	}
	return f;
}
public int email(Set<User> u,String eam){
	int i=0;
	String pat="\\w+@\\w+.(com|com.cn|cn|net|gov|edu|org)";
	Pattern p=Pattern.compile(pat);
	Matcher m=p.matcher(eam);
	if(m.matches()){
		if(checkEmai(u,eam)==1){
			i=1;
		}else{
			i=-1;
		}
		return i;
	}else{
		return 0;
	}
	

}
public int checkEmai(Set<User> u,String email){
	int f=0;
	Iterator<User> users=u.iterator();
	while(users.hasNext()){
		if(users.next().getEmail().equals(email)){
			f=1;
		}
	}
	return f;
}
}
